<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('模板列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			
	        <div class="btn-group-sm" id="toolbar" role="group">
	        	<form id="formId">
	        		<input type="hidden" id="url" name="url"/>
	        	</form>
	            <a class="btn btn-danger multiple disabled" onclick="javascript:batchForceLogout()" shiro:hasPermission="monitor:online:batchForceLogout">
	                <i class="fa fa-sign-out"></i> 导入
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-table-export-js" />
	<script th:inline="javascript">
		var forceFlag = [[${@permission.hasPermi('monitor:online:forceLogout')}]];
		var prefix = ctx + "cms/template";
		$(function() {
		    var options = {
		        url: prefix + "/list",
		        escape: true,
		        pagination: false,
		        showSearch: false,
		        showToggle: false,
		        showColumns: false,
		        params:{
		        	url:$("#url").val()
		        },
		        columns: [
		        {
		            field: 'name',
		            title: '名称',
		            formatter: function(value, row, index) {
		            	var str = '';
		            	if(row.type =='目录'){
		            		str = '<i class="fa fa-folder"></i>'
		            	}else{
		            		str = '<i class="fa fa-file-code-o"></i>'
		            	}
                    	return str+value;
                    }
		        },
		        {
		            field: 'url',
		            title: '路径'
		        },
		        {
		            field: 'type',
		            title: '类型'
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if(row.type=='目录'){
		            		actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="view(this)"><i class="fa fa-folder-open"></i>进入</a> ');
		            	}
		            	if(row.type=='文件'){
		            		actions.push(' <a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="edit(this)"><i class="fa fa-edit"></i>编辑</a> ');
		            	}
                        actions.push(' <a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="view(\'' + row.url + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		// 单条强退
		function view(row) {
			$("#url").val($(row).parent().parent().find("td").eq(1).text());
		    $.table.search();
		}
		
		function edit(row){
			var url = prefix+"/edit/"+encodeURIComponent(encodeURIComponent($(row).parent().parent().find("td").eq(1).text()));
			$.modal.openTab("模板编辑", url);
		}

		// 批量强退
		function batchForceLogout() {
		    var rows = $.table.selectColumns("sessionId");
		    if (rows.length == 0) {
		        $.modal.alertWarning("请选择要强退的用户");
		        return;
		    }
		    $.modal.confirm("确认要强退选中的" + rows.length + "条数据吗?", function() {
		        var url = prefix + "/batchForceLogout";
		        var data = { "ids": rows.join() };
		        $.operate.post(url, data);
		    });
		}
	</script>
</body>
</html>